package com.niit.service.impl;

import com.niit.entity.User;
import com.niit.mapper.UserMapper;
import com.niit.service.UserService;
import com.niit.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2024-06-06 17:56:30
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
/*    @Override
    public User queryById(Object id) {
        return Result.ok().setData(this.userMapper.queryById(id));
    }*/

    @Override
    public Result queryById(Integer id) {
        return null;
    }

    /**
     * 全查询
     *
     * @param user 筛选条件
     * @return 查询结果
     */
    @Override
    public Result queryAll(User user) {
        return Result.ok().setData(this.userMapper.queryAll(user));
    }

    /**
     * 新增数据
     *
     * @param user 实例对象
     * @return 实例对象
     */
    @Override
    public Result insert(User user) {
        this.userMapper.insert(user);
        return Result.ok().setData(user);
    }

    /**
     * 修改数据
     *
     * @param user 实例对象
     * @return 实例对象
     */
    @Override
    public Result update(User user) {
        this.userMapper.update(user);
        return Result.ok().setData(this.queryById(user.getId()));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public Result deleteById(Integer id) {
        boolean del = this.userMapper.deleteById(id) > 0;
        return Result.ok().setData(del);
    }

    @Override
    public Result findByUsername(String username) {
        return Result.ok().setData(this.userMapper.findByUsername(username));

    }
}

